package com.demon.mutehelper.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.demon.mutehelper.bean.MuteRecord
import com.demon.mutehelper.dao.MuteRecordDao

@Database(entities = [MuteRecord::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
  abstract fun muteRecordDao(): MuteRecordDao

  companion object {
    @Volatile
    private var INSTANCE: AppDatabase? = null

    fun getDatabase(context: Context): AppDatabase {
      return INSTANCE ?: synchronized(this) {
        val instance =
          Room.databaseBuilder(context, AppDatabase::class.java, "app_database").build()
        INSTANCE = instance
        instance
      }
    }
  }
}